#ifndef FPLAYER_IENCODER_H
#define FPLAYER_IENCODER_H

#include "FFMpegHeader.h"
#include "MediaDefine.h"

//枚举 编码器状态
enum EncoderState {
  EncoderState_None = 0,
  EncoderState_Init,      //初始化完成状态
  EncoderState_Release,   //释放完状态
  EncoderState_Encode,    //编码状态
};

//结构体 视频编码器参数
typedef struct ST_EncoderParam : public IBasic {
  int32_t width = 0;
  int32_t height = 0;
  int32_t frameRate = 0;
  int32_t bitRate = 0;

  const char *getClassName() override {
    return "EncoderParam";
  }

  void toString() override {
    LOG_TEST("EncoderParam(width:%d,height:%d,frameRate:%d,bitRate:%d)",
             width, height, frameRate, bitRate)
  }
} EncoderParam;

class IEncoder;

//类 编码器数据回调
class IEncodeCallback {
public:
  IEncodeCallback() = default;

  virtual ~IEncodeCallback() = default;

  /**
   * 编码完后的数据回调
   * @param pEncoder 编码器
   * @param pPacket  一帧数据编码后的数据
   */
  virtual void onEncodeData(IEncoder *pEncoder, AVPacket *pPacket) = 0;
};


//类 定义编码器
class IEncoder : public IBasic {
protected:
  //编码回调函数
  IEncodeCallback *_pEncodeCallback = nullptr;

  EncoderState _State = EncoderState_None;
public:
  explicit IEncoder(IEncodeCallback *_pEncodeCallback)
      : IBasic(), _pEncodeCallback(_pEncodeCallback) {

  }

  virtual ~IEncoder() = default;

  /**
   * 初始化编码器
   * @param encoderParam 编码器
   * @return true is Success
   */
  virtual bool initEncoder(EncoderParam &encoderParam) = 0;

  /**
   * 释放编码器
   */
  virtual void releaseEncoder() = 0;

  /**
   * 开始编码
   * @param pFrame 待编码的数据包
   */
  virtual bool startEncode(AVFrame *pFrame) = 0;

  /**
   * 编码的媒体类型
   * @return 媒体类型
   */
  virtual MediaType getMediaType() = 0;
};

#endif //FPLAYER_IENCODER_H
